/*
.......... Isochronic semi-primes for any year (leap or not) counting in hours.
..........
.......... Author: R. J. Cano, On Sun Jun 22 2015 01:01 GMT.
..........
.......... Outlined with an example:
..........
.......... 100 days have elapsed on Apr 11th until the 20hrs for any not-leap year, and there exists a time such that
.......... a semi-prime number of hours (2419) have elapsed and given p*q its prime factorisation, by replacing
.......... * with +, the resulting sum p+q match the count of already fully elapsed days, since the new year until
.......... the hour leap before the specified time (So, for 20hrs this description refers to 19:59hrs. Also by
.......... "new year" it is understood "Jan 1st 00:00h").
..........
.......... This script identifies the set of 8 semi-primes satisfying this definition. 4 of them for a not-leap
.......... year and the other 4 corresponding to a leap year. A sample dump of its execution output for this
.......... script is shown below.
*/

/* Pari-GP sourcecode stub - begin */

/* Working firstly in hours. */

look=(month=1,day=1,hour=0)->{my(distro=[31,28,31,30,31,30,31,31,30,31,30,31],c);c+=sum(k=1,month-1,distro[k]);c+=day-1;c*=24;c+=hour-1;(c>=0)*c};

sequence(oeis=1,isLeap=0)={my(cc,yy=-1,ss=[31,28+!(!isLeap),31,30,31,30,31,31,30,31,30,31],ww=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],terms,expected=4);for(mm=1,12,for(dd=1,ss[mm],yy++;for(hh=0,23,cc=look(mm,dd,hh);if((bigomega(cc+!cc)==2)&&(vecsum(factor(cc)[,1])==yy),terms++;print1(cc);if(oeis,if(terms<expected,print1(", ")),print(" "ww[mm]" "dd" "hh"h ("vecsum(factor(cc)[,1])" days).")))))); terms};

/* About the following versions: Now, by working in minutes in a similar way, nothing is found out. UNLESS:
   We look for comparisons against elapsed hours instead of elapsed days. */

look2=(month=1,day=1,hour=0,minu=0)->{my(distro=[31,28,31,30,31,30,31,31,30,31,30,31],c);c+=sum(k=1,month-1,distro[k]);c+=day-1;c*=24;c+=hour-1;c*=60;c+=minu-1;(c>=0)*c};

sequence2(oeis=1,isLeap=0)={my(cc,yy0=-1,yy=-1,ss=[31,28+!(!isLeap),31,30,31,30,31,31,30,31,30,31],ww=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],terms,expected=(13-2*isLeap));for(mm=1,12,for(dd=1,ss[mm],yy0++;for(hh=0,23,yy++;for(ii=0,59,cc=look2(mm,dd,hh,ii);if((bigomega(cc+!cc)==2)&&(vecsum(factor(cc)[,1])==yy),terms++;print1(cc);if(oeis,if(terms<expected,print1(", ")),print(" "ww[mm]" "dd" "hh"h "ii"min ("vecsum(factor(cc)[,1])" hours; Around "yy0" in days)."))))))); terms};

/* Seconds versus elapsed minutes */

look3=(month=1,day=1,hour=0,minu=0,seconds=0)->{my(distro=[31,28,31,30,31,30,31,31,30,31,30,31],c);c+=sum(k=1,month-1,distro[k]);c+=day-1;c*=24;c+=hour-1;c*=60;c+=minu-1;c*=60;c+=seconds-1;(c>=0)*c};

sequence3(oeis=1,isLeap=0)={my(cc,yy0=-1,yy=-1,ss=[31,28+!(!isLeap),31,30,31,30,31,31,30,31,30,31],ww=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],terms,expected=10000/*Unknown*/);for(mm=1,12,for(dd=1,ss[mm],yy0++;for(hh=0,23,for(ii=0,59,yy++;for(zz=0,59,cc=look3(mm,dd,hh,ii,zz);if((bigomega(cc+!cc)==2)&&(vecsum(factor(cc)[,1])==yy),terms++;print1(cc);if(oeis,if(terms<expected,print1(", ")),print(" "ww[mm]" "dd" "hh"h "ii"min "zz"secs ("vecsum(factor(cc)[,1])" minutes; Around "yy0" in days).")))))))); terms};


/* Pari-GP sourcecode stub - end */

/* Sample output of this script:

? sequence(0,1)
2279 Apr 6 0h (96 days).
2479 Apr 14 8h (104 days).
3193 May 14 2h (134 days).
3973 Jun 15 14h (166 days).
? sequence(0)
2419 Apr 11 20h (100 days).
3317 May 19 6h (138 days).
3379 May 21 20h (140 days).
4031 Jun 18 0h (168 days).

*/

/* Verified Ok against: http://www.timeanddate.com/date/duration.html */

/*
.......... Further research:
..........
..........  To implement the same detection method explained above but now for minute leap or
..........  second leap instead of hour leap. This is: Based upon smaller time units than the hour.
..........
..........  QUESTION: By changing the time units, would it exists an infinite (a non enumerable)
..........            class consisting of finite sets of semi-primes satisfying this kind of
..........            definition???
*/